﻿@using Step4.Unit2.Controllers;
@model List<Student>
@{
    ViewData["Title"] = "Search";
}
<table class="table table-hover">
    <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var student in Model)
        {
            <tr>
                <td>@student.Id</td>
                <td>@student.Name</td>
            </tr>
        }
    </tbody>
</table>


<!--表单请求-->
<form method="get" >
    姓名: <input type="text" name="studentName" id="studentName" />
    <input type="submit" value="查询"/>
</form>

<!--使用Ajax发送请求-->
<!--Razoryemian-->
@section Scripts
{
    <script>
        $('form').on('submit', () => {
            $.ajax({
                type: 'get',
                url: '/requesttest/mylist',
                data: { studentName: $("#studentName").val() },
                headers: { // 设置请求头
                    'mytoken': encodeURIComponent('余冰') // 如果是中文一定要对其进行编码 js中"encodeURIComponent()"方法用来给中文进行"编码"
                }
            });
            return false;
        })
    </script>
}